<template>
	<view class="Roster" style="height: 100%;">
		<view class="selectTime">
			<!-- <u-button @click="show = true">打开</u-button> -->
			<view class="picker-input"  @click="show = true">
				<text>{{startDeta}}</text>
				<image src="/static/img/ic_down_black.png" mode="widthFix" style="width: 10px;"></image>
			</view>
			<u-picker mode="time" v-model="show" :params="params"   @confirm="statconfirm">
				
			</u-picker>
			
		</view>
		<view class="concent-title">
			<view class="">
				{{UserInfo.user.userName}}
			</view>
			<view class="" v-if="info.one == null">
				尚未获得
			</view>
			<view class="" v-else>
				已获得
			</view>
		</view>
		<view class="list-box">
			<view class="list-box-list">
				<mescroll-uni :fixed="false" @init="mescrollInit" :height="height" :down="downOption" @down="downCallback"
					:up="upOption" @up="upCallback" @emptyclick="emptyClick">
					<view class="mescroll-item" v-for="(item,index) in goods">
						<view class="mescroll-item-text">
							<view class="title">
								{{item.userName}}
							</view>
							<view class="amt">
								{{item.bonusAmt}}
							</view>
						</view>
					
					</view>
				
				</mescroll-uni>
			</view>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	const api = require('../../config/api');
	const util = require('../../utils/util');
	import number from '../../utils/number.js'
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				number: number, //声明number属性并赋值为引入的number模块
				downOption: {
					auto: true //  false 不自动加载 (mixin已处理第一个tab触发downCallback)  true
				},
				upOption: {
					auto: false, // 不自动加载
					noMoreSize: 4,
					textLoading: '加载中 ...', // 加载中的提示文本
					textNoMore: '暂无更多', // 没有更多数据的提示文本
					empty: {
						tip: '暂无相关数据', // 提示
					},
				},
				startDeta: currentDate,
				goods: [],
				UserInfo:{},
				params: {
									year: true,
									month: true,
									day: false,
									hour: false,
									minute: false,
									second: false
								},
								show: false,
								type:''
			}
		},
		onLoad(o) {
			this.goods = uni.getStorageSync('bonusAmtlist')
			console.log(this.goods);
			this.type = o.type
		},
		onShow() {
	this.getUserInfo();

		},
		methods: {
			async getUserInfo() {
				const res = await util.request(
					api.getUserInfoUrl, {
						
					},
					'POST'
				);
				console.log(res);
				if (res.code !== 0) {
					uni.showToast({
						title: res.msg,
						icon: "none"
					})
			
				} else {
					this.UserInfo = res.data
					
				}
			},
			statconfirm(e) {
				this.startDeta = '';
				if (this.params.year) this.startDeta += e.year;
				if (this.params.month) this.startDeta += '-' + e.month;
				this.downCallback();
			},
			 getDate(type) {
			            const date = new Date();
			            let year = date.getFullYear();
			            let month = date.getMonth() + 1;
			            let day = date.getDate();
			
			            if (type === 'start') {
			                year = year - 60;
			            } else if (type === 'end') {
			                year = year + 2;
			            }
			            month = month > 9 ? month : '0' + month;
			            day = day > 9 ? day : '0' + day;
			            return `${year}-${month}`;
			        },
			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				//联网加载数据
				// this.mescroll.endErr();
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
				const res = util.request(
					api.bonusListUrl, {
						page: pageNum,
						limit: pageSize,
						type:this.type,
						date:this.startDeta
						
					},
					'GET'
				).then(res => {
					// console.log(res);
					//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
					// let totalPage = res.data.pages;
					// this.mescroll.endByPage(res.data.list.length, totalPage); //必传参数(当前页的数据个数, 总页数)
					//设置列表数据
					if (page.num == 1) this.goods = []; //如果是第一页需手动制空列表
					this.goods = this.goods.concat(res.data.list); //追加新数据
					this.mescroll.endSuccess(res.data.list.length)
				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
			//点击空布局按钮的回调
			emptyClick() {
				uni.showToast({
					title: '点击了按钮,具体逻辑自行实现'
				})
			}
		}
	}
</script>

<style>
	page {
		height: 100%;
		background-color: #F4F4F4;
	}

	.mescroll-upwarp {
		min-height: 0rpx !important;
	}
</style>
<style lang="scss" scoped>
	.mescroll-item {
		background-color: #fff;
		// width: 100%;
		// margin: 5px 0;
		margin: 5px 15px 0px 15px;
		padding: 10px;
		font-size: 14px;
		border-radius: 10px;
	}

	.mescroll-item-text {
		display: flex;
		align-items: center;
		justify-content: space-between;

	}

	.title {
		font-size: 16px;
		color: #000;
		font-weight: 600;
	}

	.amt {

		color: #6A9FFB;
	}

	.mescroll-item-time {
		margin-top: 5px;
		color: #929292;
	}

	.kong {
		box-sizing: border-box;
		width: 100%;
		padding: 100rpx 50rpx;
		text-align: center;
	}

	.kongtext {
		margin-top: 20rpx;
		font-size: 24rpx;
		color: gray;
	}

	.selectTime {
		padding-left: 15px;
		background-color: #fff;
		height: 40px;
		color: #000;
		font-size: 14px;
		text-align: left;
		line-height: 40px;
	}
	.picker-input{
		display: flex;
		align-items: center;
		image{
			margin-left: 5px;
		}
	}
	.concent-title {
		background-color: #D2E1FC;
		height: 40px;
		color: #6A9FFB;
		font-size: 14px;
		text-align: center;
		// line-height: 40px;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-left: 15px;
		margin-right: 15px;
		margin-top: 15px;
		padding-left: 5px;
		padding-right: 5px;
	}
	.list-box {
		flex: 1;
		// padding: 10px;
		width: 100%;
		overflow: hidden;
	}
	
	.list-box-list {
		margin-top: 5px;
		/* background-color: antiquewhite; */
		width: 100%;
		height: 100%;
	}
	.Roster{
		display: flex;
		flex-direction: column;
	}
</style>